package com.kmzx.one.project.controller;

import com.github.pagehelper.Page;
import com.kmzx.one.project.entity.FrequentlyAskedQuestion;
import com.kmzx.one.project.net.BaseResult;
import com.kmzx.one.project.others.dto.FAQData;
import com.kmzx.one.project.service.FAQService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Api(tags = "快美甄选_[ 常见问题_接口 ]")
@RestController
public class FAQController extends BaseController {
    @Autowired
    private FAQService faqService;

    @ApiOperation(value = "1.查询常见问题列表", notes = "1.查询常见问题列表",position = -1)
    @GetMapping(value = "faq/all")
    public BaseResult findAll() {
        try {
            //List<FAQTypeEnum> types = FAQTypeEnum.convertList();
            List<FAQData> list = new ArrayList<>();
            for (int i = 0; i < 4; i++) {
                FAQData data = new FAQData();
                switch (i) {
                    case 0:
                        data.setTypeValue(0);
                        data.setTypeName("全部");
                        break;
                    case 1:
                        data.setTypeValue(1);
                        data.setTypeName("会员");
                        break;
                    case 2:
                        data.setTypeValue(2);
                        data.setTypeName("购物");
                        break;
                    case 3:
                        data.setTypeValue(3);
                        data.setTypeName("售后");
                        break;
                }
                list.add(data);
            }
            return BaseResult.Builder.SUCC().initSuccData(list);
        } catch (Exception e) {
            return handleException(e);
        }
    }

    @ApiOperation(value = "2.根据ID查询常见问题详情", notes = "2.根据ID查询常见问题详情",position = -1)
    @GetMapping(value = "faq/single")
    public BaseResult findSingle(Integer pageNum, Integer pageSize, Integer type) {
        try {
            pageNum = pageNum == null ? super.pageNum : pageNum;
            pageSize = pageSize == null ? super.pageSize : pageSize;
            Page<FrequentlyAskedQuestion> data = faqService.findFrequentlyAskedQuestionsByType(pageNum, pageSize, type);
            if (data != null) {
                return BaseResult.Builder.SUCC().initSuccData(data.getResult());
            }
        } catch (Exception e) {
            return handleException(e);
        }
        return BaseResult.Builder.FAIL();
    }
}
